package com.rsk.api;


import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.SysCompanyContactsService;
import com.rsk.service.SysCompanyTypesService;
import com.rsk.utils.result.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.QueryParam;

/**
 * 机构联系人
 * @author myr
 */

@RestController
@RequestMapping(value="/sys/comcontacts")
public class SysCompanyContactsApi {

    @Reference(interfaceClass = SysCompanyTypesService.class, protocol = "dubbo")
    private SysCompanyContactsService sysCompanyContactsService;

    /**
     * 删除机构联系人
     * @param id
     * @param Authorization
     * @return
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping(value="/delSysCompanyContacts" )
    public Result<String> delSysCompanyContacts(@QueryParam("id") Long id,
                                             @RequestHeader("Authorization") String Authorization){
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysCompanyContactsService.delSysCompanyContacts(id, operatorUser);
        return ReturnUtils.returnDataByOne(i);
    }

    /**
     * 修改机构联系人
     * @param companyId
     * @param contactsName
     * @param contactsPhone
     * @param contactsPost
     * @param remarks
     * @param Authorization
     * @param mainResponsiable  是否为主联系人
     * @return
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping(value="/updateSysCompanyContacts")
    public Result<String> updateSysCompanyContacts(@QueryParam("id") Long id,
                                                   @QueryParam("companyId") Long companyId,
                                                @QueryParam("contactsName") String contactsName,
                                                @QueryParam("contactsPhone")  String contactsPhone,
                                                @QueryParam("contactsPost") String contactsPost,
                                                @QueryParam("remarks") String remarks,
                                                @QueryParam("mainResponsiable") Integer mainResponsiable,
                                                @RequestHeader("Authorization") String Authorization){
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysCompanyContactsService.updateSysCompanyContacts(id,companyId,contactsName,contactsPhone,contactsPost,remarks,operatorUser,mainResponsiable);
        return ReturnUtils.returnDataByOne(i);
    }

    /**
     * 新增机构联系人
     * @param id
     * @param companyId  机构Id
     * @param contactsName  联系人姓名
     * @param contactsPhone  联系人电话
     * @param contactsPost   联系人职务
     * @param remarks        备注
     * @param Authorization
     * @return
     */
    //@RequiresPermissions("sys_users:save")
    @PostMapping(value="/saveSysCompanyContacts")
    public Result<String> saveSysCompanyContacts(@QueryParam("id") Long id,
                                              @QueryParam("companyId") Long companyId,
                                              @QueryParam("contactsName") String contactsName,
                                              @QueryParam("contactsPhone") String contactsPhone,
                                              @QueryParam("contactsPost") String contactsPost,
                                              @QueryParam("remarks")  String remarks,
                                              @QueryParam("mainResponsiable") Integer mainResponsiable,
                                              @RequestHeader("Authorization") String Authorization){
        //String operatorUser = JwtUtil.getClaim(Authorization, "account");
        Long operatorUser = 123L;
        int i = sysCompanyContactsService.saveSysCompanyContacts(id,companyId,contactsName,contactsPhone,contactsPost,remarks,operatorUser,mainResponsiable);
        return ReturnUtils.returnDataByOne(i);
    }

}
